home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Contributed / SpriteWorld / SpriteWorld Files / Utils / SWFPSReport.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  2.0 KB  |  71 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    SWFPSReport.c
  3. //
  4. //    Requires ALRT and DITL resource ID 200 to be copied from SpriteTest and put in 
  5. //    your project. Remember to include the SWFPSReport.h file as well. It will 
  6. //    call SysBeep if for some reason it can't display the alert.
  7. //
  8. //    Make sure to set the Sprite's move time and the MaxFPS rate to 0; otherwise 
  9. //    the fps report will be innaccurate. (It still isn't terribly accurate, but should
  10. //    give you a pretty good idea of how fast the animation is going.)
  11. ///--------------------------------------------------------------------------------------
  12.  
  13. #ifndef __TOOLUTILS__
  14. #include <ToolUtils.h>
  15. #endif
  16.  
  17. #ifndef __TEXTUTILS__
  18. #include <TextUtils.h>
  19. #endif
  20.  
  21. #include <SWFPSReport.h>
  22.  
  23. #define    kNoteAlertID    200
  24.  
  25.  
  26. long            gOldTicks;
  27.  
  28.  
  29. ///--------------------------------------------------------------------------------------
  30. //    Call StartTimer right before you start the animation
  31. ///--------------------------------------------------------------------------------------
  32.  
  33. void    StartTimer( void )
  34. {
  35.         // Wait for ticks to roll over before starting
  36.     gOldTicks = TickCount();
  37.     while (gOldTicks == TickCount())
  38.         ;
  39.  
  40.     gOldTicks = TickCount();
  41. }
  42.  
  43.  
  44. ///--------------------------------------------------------------------------------------
  45. //    Call ShowResults as soon as your animation is done and pass to it the number of
  46. //    frames that have occured in the animation.
  47. ///--------------------------------------------------------------------------------------
  48.  
  49. void    ShowResults( long frames )
  50. {
  51.     Str255         framesString, secondsString, fpsString;
  52.     long         fps;
  53.     double        seconds;
  54.     
  55.     seconds = ((TickCount() - gOldTicks - 1) / 60.5);
  56.     fps = (double)frames / seconds;
  57.  
  58.     NumToString(frames, framesString);
  59.     NumToString(seconds, secondsString);
  60.     NumToString(fps, fpsString);
  61.  
  62.     ParamText(framesString, secondsString, fpsString, "\p");
  63.     
  64.     SetCursor(&qd.arrow);
  65.     ShowCursor();
  66.     
  67.     if (NoteAlert(kNoteAlertID, NULL) == -1)
  68.         SysBeep(10);
  69. }
  70.  
  71.